package cn.ecut.request;

import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Part;
import java.io.IOException;
import java.util.Collection;

/**
 * @author lujiapeng
 * @className MultipleFileUploadServlet
 * @description TODO
 * @date 2020/9/11 10:46
 **/
@WebServlet(value = "/multipleFileUpload" )
@MultipartConfig(location = "C:/files")
public class MultipleFileUploadServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        throw new RuntimeException("不支持Get方式上传文件") ;
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Collection<Part> parts = request.getParts();
        for (Part part : parts) {
            part.write( part.getSubmittedFileName() );
        }
    }
}
